/*
package study.web.servlet;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import study.pojo.Brand;
import study.pojo.LoginBean;
import study.pojo.User;
import study.service.impl.BrandServiceImpl;
import study.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet("/user/*")
public class UserServlet extends BaseServlet{
    private UserServiceImpl service=new UserServiceImpl();
    public void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BufferedReader reader = req.getReader();
        String s = reader.readLine();

        User u = JSON.parseObject(s, User.class);


        User user = service.login(u.getUsername(), u.getPassword());


        if(user!=null){
            //登陆成功
            //判断复选框是否选中
            //当equal比较时有字符串，字符串放前面，防止变量为空报错

            //将登陆成功后的User对象存储到Session中
            HttpSession session = req.getSession();
            session.setAttribute("user",user);

            //响应成功
            resp.getWriter().write("success");

        }else{
            //登陆失败
            resp.getWriter().write("fail");
        }


    }

}
*/
